import { defineStore } from 'pinia';
import { getHospitalDetail, getHospitalDeparment } from '@/api/hospital';
import { HospitalDetail, DeparmentArr } from '@/api/hospital/type';

interface State {
	hospitalDetail: HospitalDetail;
	deparmentArr: DeparmentArr;
}

export const useHospitalDetailStore = defineStore('detail', {
	state(): State {
		return {
			hospitalDetail: {} as HospitalDetail,
			deparmentArr: [],
		};
	},
	actions: {
		// 获取医院详情
		getHospitalDetail(hoscode: string, fn?: Function) {
			getHospitalDetail(hoscode)
				.then((res) => {
					if (res.code === 200) {
						this.hospitalDetail = res.data;
					}
				})
				.finally(() => {
					fn && fn();
				});
		},
		// 获取医院科室数据
		getHospitalDeparment(hoscode: string) {
			getHospitalDeparment(hoscode).then((res) => {
				if (res.code === 200) {
					this.deparmentArr = res.data;
				}
			});
		},
	},
	getters: {},
});
